const BaseX = require('base-x');

var bs58alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';//少了0 O l 这三个
var bs58 = BaseX(bs58alphabet);

const Base58 = {
  encode: function (source: any): any {
    if (typeof source == 'string') {
      var buffer = [];
      for (var i = 0; i < source.length; i++) {
        buffer.push(source.charCodeAt(i));
      }

      return this.encode(buffer);
    }

    return bs58.encode(source);
  },
  decode: function (source: any) {
    return String.fromCharCode.apply(source, bs58.decode(source));
  },
  decodeArray: function (source: any) {
    return bs58.decode(source);
  }
};

export default Base58;
